package com.bili.bili_data_api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bili.bili_data_api.dao.mapper.WolongsidateMapper;
import com.bili.bili_data_api.dao.mapper.WolongsitypeMapper;
import com.bili.bili_data_api.dao.pojo.Wolongsidate;
import com.bili.bili_data_api.dao.pojo.Wolongsitype;
import com.bili.bili_data_api.service.WlsService;
import com.bili.bili_data_api.vo.TypeList;
import com.bili.bili_data_api.vo.WlsDateVo;
import com.bili.bili_data_api.vo.WlsTypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class WlsServiceImpl implements WlsService {

    @Autowired
    private WolongsidateMapper woLongSiDateMapper;
    @Autowired
    private WolongsitypeMapper wolongsitypeMapper;

    @Override
    public WlsDateVo getWlsDate() {
        WlsDateVo wlsDateVo = new WlsDateVo();
        QueryWrapper<Wolongsidate> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("date");
        queryWrapper.last("limit 11");
        List<Wolongsidate> wolongsidates = woLongSiDateMapper.selectList(queryWrapper);
        List<String> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();
        for (Wolongsidate woLongSiDate : wolongsidates) {
            list1.add(woLongSiDate.getDate().substring(5,9));
            list2.add(woLongSiDate.getNum());
        }
        wlsDateVo.setDateList(list1);
        wlsDateVo.setNumList(list2);
        return wlsDateVo;
    }

    @Override
    public WlsTypeVo getWlsType() {
        WlsTypeVo wlsTypeVo = new WlsTypeVo();
        QueryWrapper<Wolongsitype> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("num");
        queryWrapper.last("limit 8");
        List<Wolongsitype> wolongsitypes = wolongsitypeMapper.selectList(queryWrapper);
        List<TypeList> typeList = new ArrayList<>();
        for (Wolongsitype wolongsitype : wolongsitypes) {
            TypeList list = new TypeList();
            list.setName(wolongsitype.getType());
            list.setValue(wolongsitype.getNum());
            typeList.add(list);
        }
        wlsTypeVo.setTypeList(typeList);
        return wlsTypeVo;
    }
}
